<?php
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Validate;
use think\Db;
use app\admin\model\RepresentModel;
class RepresentController extends AdminBaseController
{
     public function index()
     {
          return $this->fetch();
     }
     public function list()
     {
          $levelinfo=Db::name('represent_list')->select()->toArray();
          return $this->fetch('Represent/list',[
            'listinfo'=>$levelinfo
            ]);
     }
      //修改页面
      public function listedit()
     {
           $data = $this->request->param();
          $res=RepresentModel::where('id',$data['id'])->find()->toArray();
          return $this->fetch('Represent/listedit',[
            'res'=>$res
            ]);
     }
      //修改操作
       public function listeditt()
     {
          $data = $this->request->param();
          $time = time();
          $level=new RepresentModel();
          $add=$level->where('id',$data['id'])->update(['create_time'=>$time,'name'=>$data['name'],'phone'=>$data['phone'],'idcard'=>$data['idcard'],'city'=>$data['city'],'superior'=>$data['superior'],'status'=>$data['status']]);
          if($add == 1)
          {
            $this->success('修改成功');
          }else{
            $this->error('修改失败');
          }
     }
      //删除操作
     public function listdelete()
     {
            $data = $this->request->param();
            $res=RepresentModel::destroy($data['id']);
            if($res ==1){
                $this->success('删除成功');
            }else{
                $this->error('添加失败');
            }
     }
      //代表筛选
     public function screen()
    {
        $data = $this->request->param();
        if($data['keyword'] != "")
        {
            $map['name'] = array('like', '%' . $data['keyword'] . '%');
            $listinfo=Db::name('represent_list')->where($map)->select()->toArray();
        }else if($data['category'] !=""){
            $listinfo=Db::name('represent_list')->where('status',$data['category'])->select()->toArray();
        }else{
             $listinfo=Db::name('represent_list')->select()->toArray();
        }
        return $this->fetch('Represent/list',[
            'listinfo'=>$listinfo
        ]);

    }

}
